<template>
	<view class="">
		<view class="" style="background: #fff;">
			<view class="">
				<view class="bg" :class="title != '' ? 'bg-color' : ''">
			
					<u-icon @click="goBack" size="36" name="arrow-left"></u-icon>
					<text>{{title}}</text>
					<view class="">
					</view>
				</view>
			</view>
			<view class="time">
				<view class="time-item" v-for="(item,index) in nextSevenDays" :key="index" @click="selecTime(item,index)">
			
					<view class="week" :class="{'color-h':isindex==index}">
						{{item.weekday}}
					</view>
					<view class="month" :class="{'color-h':isindex==index}">
						{{item.monthDay}}
					</view>
				</view>
			</view>
			<view class="pull">
				<pullDown @inquire="inquire" @select="select" @reset="reset" :levelList="synthesis" :isTrue="true"
					:sort="medicSynthesis" />
			</view>
		</view>



		<view class="synthesis">
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltolower="lower">

				<view class="">
					<view class="doctorCard" v-if="sort.length>0">
						<view class="card-item" v-for="(item,index) in sort" :key="item,id" @click="department(item)">
							<doctorCard :card="item" :levelList="synthesis" />
						</view>
					</view>
					<view class="box-empty" v-else>
						<u-empty text="未找到相关医生" mode="list"></u-empty>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		toast,
		getStore,
		setStore,
		removeStore
	} from "@/utils/index";
	import pullDown from '../../components/pullDown.vue';
	import doctorCard from '../../components/doctorCard.vue';
	import {
		getregistration,
		doctorList
	} from '../../service/api.js'
	export default {
		components: {
			pullDown,
			doctorCard,

		},

		computed: {
			// 将 `getNextSevenDaysFormatted` 放入计算属性中
			nextSevenDays() {
				const days = [];
				const today = new Date(); // 获取今天的日期

				// 自定义获取周几的方法
				const getWeekday = (date) => {
					const weekdays = ['日', '一', '二', '三', '四', '五', '六'];
					return `周${weekdays[date.getDay()]}`;
				};

				for (let i = 0; i < 7; i++) {
					const nextDay = new Date(today); // 创建一个新的日期对象，避免修改原始的 today
					nextDay.setDate(today.getDate() + i); // 设置新日期为今天加上 i 天

					// 获取月和日
					const month = nextDay.getMonth() + 1; // 月份是从0开始的，因此需要加1
					const day = nextDay.getDate();

					// 格式化日期：例如：11.25
					const monthDay = `${month}.${day < 10 ? '0' + day : day}`; // 保证日期两位数显示

					// 获取周几
					const formattedWeekday = getWeekday(nextDay);

					// 将月日和周几封装成对象并加入数组
					days.push({
						monthDay, // 月日，例如：11.25
						weekday: formattedWeekday // 周几，例如：周一
					});
				}

				return days;
			}
		},
		data() {
			return {
				title: "科室",
				url: "searchResults/index",
				isindex: 0,
				details: {},
				depId: 1,
				params: {
					depId: "",
					name: "",
					level: "",
					orderPrice: ""
				},
				sort: [

				],

				medicSynthesis: [{
						label: '综合排序',
						value: 2,
					},
					{
						label: '价高优先',
						value: "asc",
					},
					{
						label: '价低优先',
						value: "dsc",
					}
				],

				synthesis: [],
			}
		},
		onLoad(options) {
			this.depId = options.itemid;
			this.title = options.itemtitle;
			
			this.getdepDoctor();
			this.getlevel();
		},


		methods: {
			goBack() {


				uni.navigateBack({
					delta: 1,
				});




			},


			//请求医生等级
			async getlevel() {
				let res = await getregistration("doctor_level")
				if (res.code == 200) {
					this.synthesis = res.rows;
				}
			},
			//请求医生列表
			async getdepDoctor() {
				this.params.depId = this.depId;
				let res = await doctorList(this.params)
				if (res.code == 200) {
					// this.title = JSON.parse(getStore('office')).title;
					this.sort = res.rows;
				}
			},
			//选中时间
			selecTime(item, index) {
				this.isindex = index;
			},
			lower() {
			},
			//下拉子组件方法
			inquire(item) {
				this.params = JSON.parse(JSON.stringify({}));
				this.params.level = item;

				this.getdepDoctor()
			},
			reset(item){
				this.params.level=item;
				this.getdepDoctor()
			},
			//下拉子组件方法
			select(item) {
				this.params = JSON.parse(JSON.stringify({}));
				this.params.orderPrice = item.value;
				this.getdepDoctor()
			},
			//跳转医生详情页
			department(item) {
				item.dictLabel = this.synthesis[item.level].dictLabel
				uni.navigateTo({
					url: `/integration/doctorDetails/index?item=${JSON.stringify(item)}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.synthesis {
		// padding: 24rpx;
		background: #F5F3F0;

		.scroll-Y {
			height: calc(100vh - 415rpx);
			padding-top: 24rpx;

			.doctorCard {
				.card-item {
					margin: 0 24rpx;
					margin-bottom: 24rpx;
				}
			}
		}
	}

	.pull {
		// margin-top: 24rpx;
		padding: 24rpx;
	}



	.time {
		display: grid;
		grid-template-columns: repeat(7, 1fr);
		// gap: 20rpx;
		padding-top: 24rpx;
		text-align: center;

		.time-item {
			font-size: 24rpx;

			.week {

				color: #B3B3B3;
			}

			.month {

				color: #1A1A1A;
			}
		}

	}

	.color-h {
		color: #CCA566 !important;
	}

	.bg {
		width: 100%;
		height: 120rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 24rpx;
		padding-top: 65rpx;


		.title-img {
			width: 100rpx;
		}

		text {
			display: inline-block;

			color: #1a1a1a;
			font-size: 32rpx;
			font-weight: bold;
		}

		view {
			width: 100rpx;
		}
	}

	.bg-color {
		// background: #fff;
	}
</style>